Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
filter-obj
Advanced tools
The filter-obj npm package allows users to filter the properties of an object based on specific criteria. This can be useful for creating subsets of an object, removing unwanted properties, or selectively copying properties based on dynamic conditions.
Filtering based on property names
This feature allows you to filter an object by specifying which property names to keep. It is useful for extracting specific properties from an object.
const filterObj = require('filter-obj');
const obj = { a: 1, b: '2', c: 3 };
const filtered = filterObj(obj, ['a', 'c']);
console.log(filtered); // Output: { a: 1, c: 3 }
Filtering using a function
This feature enables filtering based on a function that takes key and value as arguments. It allows for more dynamic and condition-based filtering, such as filtering out properties based on their types or values.
const filterObj = require('filter-obj');
const obj = { a: 1, b: '2', c: 3 };
const filtered = filterObj(obj, (key, value) => typeof value === 'number');
console.log(filtered); // Output: { a: 1, c: 3 }
lodash.pick is a method from the Lodash library that creates an object composed of the picked object properties. It is similar to filter-obj but is part of a larger utility library, which might be preferable for users who need other utility functions.
object-filter is another npm package that provides similar functionality to filter-obj, allowing filtering of object properties based on a predicate function. It compares to filter-obj in terms of functionality but might have different implementation details or additional options.
Filter object keys and values into a new object
$ npm install filter-obj
import filterObject from 'filter-obj';
const object = {
foo: true,
bar: false
};
const newObject = filterObject(object, (key, value) => value === true);
//=> {foo: true}
const newObject2 = filterObject(object, ['bar']);
//=> {bar: false}
Type: object
The source object to filter properties from.
Type: (sourceKey, sourceValue, source) => boolean
A predicate function that detemines whether a property should be assigned to the new object.
Type: string[]
An array of property names that should be assigned to the new object.
FAQs
Filter object keys and values into a new object
We found that filter-obj demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.